package com.xidian.zhiancloud.service.luling.systemconfiguration;

import com.xidian.zhiancloud.dao.WarSignCategoryStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.WarSignCategoryStatus;
import com.xidian.zhiancloud.model.WarSignCategoryStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WarSignCategoryStatusService {
    @Autowired
    private WarSignCategoryStatusMapper   warSignCategoryStatusMapper;
    public Object getList(String num, String name, String personAdd, String key, int current, int size) {
        WarSignCategoryStatusExample warSignCategoryStatusExample = new WarSignCategoryStatusExample();
        WarSignCategoryStatusExample.Criteria criteria1 = warSignCategoryStatusExample.createCriteria();
        WarSignCategoryStatusExample.Criteria criteria2 = warSignCategoryStatusExample.createCriteria();
        WarSignCategoryStatusExample.Criteria criteria3 = warSignCategoryStatusExample.createCriteria();
        criteria1.andNumEqualTo(num);
        criteria2.andNumEqualTo(num);
        criteria3.andNumEqualTo(num);
        if (name != null) {
            criteria1.andNameEqualTo(name);
            criteria2.andNameEqualTo(name);
            criteria3.andNameEqualTo(name);
        }
        if (personAdd != null) {
            criteria1.andPersonAddEqualTo(personAdd);
            criteria2.andPersonAddEqualTo(personAdd);
            criteria3.andPersonAddEqualTo(personAdd);
        }
        if (key!= null && !"".equals(key)) {
            criteria1.andNameEqualTo('%' + key + '%');
            criteria2.andNumEqualTo('%' + key + '%');
            criteria3.andPersonAddEqualTo('%' + key + '%');
            warSignCategoryStatusExample.or(criteria2);
            warSignCategoryStatusExample.or(criteria3);
        }
        return warSignCategoryStatusMapper.selectByExampleWithRowbounds(warSignCategoryStatusExample, new RowBounds(current, size));
    }
    public void update(WarSignCategoryStatus warSignCategoryStatus) {
        WarSignCategoryStatusExample example = new WarSignCategoryStatusExample();
        WarSignCategoryStatusExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(warSignCategoryStatus.getId());
        WarSignCategoryStatus task = new WarSignCategoryStatus();
        task.setId(warSignCategoryStatus.getId());
        int count = warSignCategoryStatusMapper.updateByExampleSelective(task, example);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
    }

    public void delete(WarSignCategoryStatus warSignCategoryStatus) {
        WarSignCategoryStatusExample example = new WarSignCategoryStatusExample();
        WarSignCategoryStatusExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(warSignCategoryStatus.getId());
        int count = warSignCategoryStatusMapper.deleteByExample(example);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
    }
    }
    public void insert(WarSignCategoryStatus warSignCategoryStatus) {
        int count = warSignCategoryStatusMapper.insert(warSignCategoryStatus);
        if (count == 0) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
    }
    }
        }
//导入导出
